<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <link href="/resources/viewer/viewer.css" rel="stylesheet">
    <script src="/resources/viewer/viewer.js"></script>
</head>
<body>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12">
        <div class="x_panel">
            <div class="x_title">
                <h2>对冲单维护 <small></small></h2>
                <ul class="nav navbar-right panel_toolbox">

                    <li><button onclick="back()" class="btn btn-primary" type="button">返回</button>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <br>
                <div id="demo-form2"  class="form-horizontal form-label-left" >
                    <input type="hidden" id="id" name="id" class="form-data" >
                    <input type="hidden" id="saleOrderId" name="saleOrderId" class="form-data" >
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">销售记录名称
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="name" name="name"
                                   class="form-control saleOrder col-md-7 col-xs-12" readonly >
                        </div>
                    </div>





                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="timeBegin">开始时间
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="timeBegin" name="timeBegin" class="form-control saleOrder" readonly
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="timeEnd">结束时间
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="timeEnd" name="timeEnd" class="form-control saleOrder" readonly
                                   onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">销售量
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="amount" name="amount" readonly
                                   class="form-control saleOrder col-md-7 col-xs-12" >

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">采集数值
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="monitorValueLora" name="monitorValueLora" readonly
                                   class="form-control form-data col-md-7 col-xs-12" >

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">对冲数值
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <input type="text" id="offsetOrderValue" name="offsetOrderValue"
                                   class="form-control form-data col-md-7 col-xs-12" >

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12">对冲值说明
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            <textarea class="form-control form-data" name="desc" id="desc" rows="3" placeholder=""></textarea>
                        </div>
                    </div>
                    <div class="ln_solid"></div>
                    <div class="form-group">
                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                            <button onclick="save()" class="btn btn-success">提交</button>
                            <!--<button onclick="back()" class="btn btn-primary" type="button">返回</button>-->
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function () {
        initData();
    });

    function initData(){
        var data = getData();
        if(null2empty(data["saleOrderId"]) !==""){
            var saleOrderId = data.saleOrderId;
            $("input[name='saleOrderId']").val(saleOrderId);
            $.ajax({
                url:"/admin/offsetOrder/find.do",
                data:{'saleOrderId':saleOrderId},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data.saleOrder, '.saleOrder');
                        if(!isNullOrUndefined(data.data.monitorValueLora)){
                            $("[name='monitorValueLora']").val(data.data.monitorValueLora.calcValue);
                        }else{
                            $("[name='monitorValueLora']").val("0");
                        }
                        if(!isNullOrUndefined(data.data.offsetOrder)){
                            $("[name='offsetOrderValue']").val(data.data.offsetOrder.value);
                            $("#id").val(data.data.offsetOrder.id);
                            $("#desc").val(data.data.offsetOrder.desc);
                        }
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }

    function save() {
        var params = {};
        params["id"] = $("#id").val();
        params["saleOrderId"] = $("#saleOrderId").val();
        params["value"] = $("#offsetOrderValue").val();
        params["desc"] = $("#desc").val();

        $.ajax({
            url: "/admin/offsetOrder/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    var localData = getData();
                    goto(localData.back_url,{"process":localData.process,"refuseFlag":localData.refuseFlag});
                } else {
                    alert(data.msg);
                }
            }
        });
    }

    function back() {
        var localData = getData();
        goto(localData.back_url,{"process":localData.process,"refuseFlag":localData.refuseFlag});
    }
</script>
</html>